package com.tianqu.tms.www.bid.controller;


import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.AucCarInfo;
import com.tianqu.tms.entity.AucManagement;
import com.tianqu.tms.entity.Member;
import com.tianqu.tms.www.bid.viewhelper.BidCarSerchAllBidDetailViewHelper;

public class BidCarSerchAllDoneInputController extends TmsController {
	
	private static String ID = "id";
	private static String SERIAL = "serial";
	private static String BIDSTATUS = "bidStatus";
	private static String FLG = "flg";
	private Logger logger = Logger
			.getLogger(BidCarSerchAllDoneInputController.class);
	BidCarSerchAllBidDetailViewHelper view = new BidCarSerchAllBidDetailViewHelper();

	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();

		// 添加事务提交异常捕获
		try {
			controller.begin();
			
			String id = (String) uc.getAttribute(ID);
			String serial = (String) uc.getAttribute(SERIAL);
			String flg = (String) uc.getParameter(FLG);
			
			AucCarInfo auc = AucCarInfo.getInstance();
			auc = auc.findAucCarInfoBySerial(serial);

			AucManagement aucnamagement = AucManagement.getInstance();
			aucnamagement = aucnamagement.getAucInfoById(StringUtil.getint(id));
			
			Member menber = Member.getInstance();
			
			view.setId(Integer.valueOf(id));
			view.setSerial(serial);
			// 竞价状态取得
			view.setBidStatus(String.valueOf(aucnamagement.getBidStatus()));
			view.setVin(auc.getVin());
			view.setLicensePlate(auc.getLicensePlate());
			view.setMemberList(menber.findAllMemInfo(1));
			view.setFlg(flg);
			view.setMemberId(aucnamagement.getDoneMemberId());
			view.setDonePrices(StringUtil.getString(aucnamagement.getDonePrices()));
			
			uc.setAttribute(TmsConstants.VIEWHELP, view);
			logger.debug(this.getClass().getName() + "#execute was completed.");
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}
	}
}
